home *** CD-ROM | disk | FTP | other *** search
- Path: nntp.teleport.com!muse
- From: muse@teleport.com (Andrew T Millard)
- Newsgroups: comp.lang.c
- Subject: Re: Random numbers...?
- Date: 11 Jan 1996 06:54:16 GMT
- Organization: Teleport - Portland's Public Access (503) 220-1016
- Message-ID: <4d2c6o$h7l@maureen.teleport.com>
- References: <30DDBEB1.4C42@aruba.ccit.arizona.edu> <DKDz1v.736@eskimo.com>
- NNTP-Posting-Host: kelly.teleport.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- mAg (mag@eskimo.com) wrote:
- : In article <30DDBEB1.4C42@aruba.ccit.arizona.edu> (Sun, 24 Dec 1995 13:57:21 -0700),
- : vaughn@aruba.ccit.arizona.edu says :
- : >
- : >Hello,
- : >Thanks to those who helped me with my last question on
- : >cache-flushing. I realize I'm showing my newness to C by even asking
- : >this, but I need to get some code that will simply generate a random
- : >integer from 0 to 9. Specifically, I want to generate a string of
- : >four random digits. I keep generating numbers that look suspiciously
- : >non-random somehow (seeding the random number generator with the
- : >current time). Any ideas?
- : >
- : >Thanks,
- : >Bill Vaughn
-
- Bill, this routine should do fine:
-
- #include <stdio.h>
- #include <math.h>
-
- void main(void)
- {
- int iCount, digit[4];
-
- srand(time()); /* Seeds random numbers */
- for(iCount = 0; iCount <= 3; iCount++)
- {
- digit[iCount] = abs(rand() % 10);
- }
- }
-
- If this doesn't work, then the Gods are just angry at you. :)
- Newbie-man Bjornus
-
-
- --
- "There is a man, I think, who might have what you need."
- Mnemo
-
- "Heavy hung the canopy of blue..."
- Green is the Color
- Pink Floyd
-